package com.hanfu.ucenter.web.web.util;


import com.hanfu.ucenter.web.web.vo.IdGenerator;

public class StringUtil {
    //首字母转小写
    public static String toLowerCaseFirstOne(String s) {
        if (Character.isLowerCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
    }

    //首字母转大写
    public static String toUpperCaseFirstOne(String s) {
        if (Character.isUpperCase(s.charAt(0)))
            return s;
        else
            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
    }

    /**
     * 生成订单号
     *
     * @param orderType 订单类型 1 现货 2 预售
     * @return 订单号
     * @author LiuXingHai
     */
    public static String generateOrderNoWithPrefix(Integer orderType) {
        String nextId = IdGenerator.INSTANCE.nextId();
        StringBuffer orderNo = new StringBuffer();
        switch (orderType) {
            case 1:
                orderNo.append("XH").append(nextId);
                break;
            case 2:
                orderNo.append("YS").append(nextId);
                break;
            default:
                orderNo.append("XH").append(nextId);
        }
        return orderNo.toString();
    }

    /**
     * 生成订单号
     *
     * @param
     * @return 订单号
     * @author LiuXingHai
     */
    public static String generateOrderNo() {
        String nextId = IdGenerator.INSTANCE.nextId();
        return nextId;
    }

    /**
     * 生成订单号
     *
     * @param
     * @return 订单号
     * @author LiuXingHai
     */
    public static String generateLogSn() {
        String nextId = IdGenerator.INSTANCE.nextId();
        return "L"+nextId;
    }

    /**
     * 生成验证码
     *
     * @param uid
     * @return
     */
    public static String getValidCode(String uid) {
        int code = uid.hashCode();
        if (code < 0) {
            code = code * -1;
        }
        return String.valueOf(code);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(getValidCode(String.valueOf(i)));
        }
    }
}
